﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using ActionServices;
using System.Drawing;
using CoreData;
using Helper;
namespace SchoolManagementSystem.Controls
{
    class SetGridRowColor
    {
        //dinh nghĩa mảng tô màu

        public static void SetArrColor(GridView gridView1, int rowindex, object _Model, Color DefaultBack,Color DefaultFore, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (_Model.GetType() == typeof(TempStudentActionService))
            {
                var id = (long)gridView1.GetRowCellValue(rowindex, "Status");

                var data = (Student_Status)RegisterService.RegisterServices.StudentStatusService.GetByID(id);
                if (data != null && !String.IsNullOrEmpty(data.ColorText)&&data.ColorText!="-1")
                {
                    e.Appearance.BackColor = Color.FromArgb(ConvertObject.ToInt(data.ColorText));
                    e.Appearance.ForeColor = Color.White;
                }
                else
                {
                    e.Appearance.BackColor = DefaultBack;
                    e.Appearance.ForeColor = DefaultFore;
                }

            }
            if (_Model.GetType() == typeof(StudentActionService))
            {
                var id = (long)gridView1.GetRowCellValue(rowindex, "Status");

                var data = (Student_Status)RegisterService.RegisterServices.StudentStatusService.GetByID(id);
                if (data != null && !String.IsNullOrEmpty(data.ColorText) && data.ColorText != "-1")
                {
                    e.Appearance.BackColor = Color.FromArgb(ConvertObject.ToInt(data.ColorText));
                    e.Appearance.ForeColor = Color.White;
                }
                else
                {
                    e.Appearance.BackColor = DefaultBack;
                    e.Appearance.ForeColor = DefaultFore;
                }

            }
            if (_Model.GetType() == typeof(Student_ResultActionService))
            {
                var id = (long)gridView1.GetRowCellValue(rowindex, "StudentID");
                var st = ((Student)RegisterService.RegisterServices.StudentService.GetByID(id));
              //  var data = (Student_Status)RegisterService.RegisterServices.StudentStatusService.GetByID(id);
                if (st != null && st.Active==true)
                {
                    e.Appearance.BackColor = Color.DarkGray;
                    e.Appearance.ForeColor = Color.White;
                }
                else
                {
                    e.Appearance.BackColor = DefaultBack;
                    e.Appearance.ForeColor = DefaultFore;
                }
            }
        }
    }
}
